<?php 

/**
 * this class provies functions for writing to files
 * @author 		simon ungerboeck <ungerboeck_simon@hotmail.com>
 * @version		1.0
 */
class FileWriter {
	private $file;
	private $dir;
	private $action;

	/**
	 * sets the variables
	 * @param 		string		 $dir
	 * @param 		string		 $file
	 */
	public function __construct($dir, $file, $action) {
		$this->file = $dir . '/' . $file;
		$this->dir = $dir;
		$this->action = $action;
	}


	/**
	 * checks if file and directory exists, if not -> 
	 * create and write logtext to file
	 * @param		string		$text
	 */
	public function writeLine($text) {
		$fp = fopen($this->file, $this->action);
		flock($fp, 2);
		fwrite($fp, $text);
		flock($fp, 3);
		fclose($fp);
	}
}
?>